Sensor Fusion for Kinetis MCUs (ISSDK/KSDK version)
sensor_fusion.h File Reference
+ Include dependency graph for sensor_fusion.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  PhysicalSensor
 
struct  PressureSensor
 
struct  AccelSensor
 
struct  MagSensor
 
struct  GyroSensor
 
union  FifoSensor
 
struct  SV_1DOF_P_BASIC
 
struct  SV_3DOF_G_BASIC
 
struct  SV_3DOF_B_BASIC
 
struct  SV_3DOF_Y_BASIC
 
struct  SV_6DOF_GB_BASIC
 
struct  SV_6DOF_GY_KALMAN
 
struct  SV_9DOF_GBY_KALMAN
 
struct  SV_COMMON
 
struct  SensorFusionGlobals
 

Macros

#define CHZ   2
 
#define true   1
 
#define false   0
 
#define GTOMSEC2   9.80665
 
#define SPI_ADDR   0x00
 
Vector Components

Index values for accessing vector terms

#define CHX   0
 
#define CHY   1
 
Generic bit-field values

Generic bit-field values

#define B0   (1 << 0)
 
#define B1   (1 << 1)
 
#define B2   (1 << 2)
 
#define B3   (1 << 3)
 
Math Constants

useful multiplicative conversion constants

#define PI   3.141592654F
 
#define PIOVER2   1.570796327F
 
#define FPIOVER180   0.01745329251994F
 
#define F180OVERPI   57.2957795130823F
 
#define F180OVERPISQ   3282.8063500117F
 
#define ONETHIRD   0.33333333F
 
#define ONESIXTH   0.166666667F
 
#define ONESIXTEENTH   0.0625F
 
#define ONEOVER12   0.083333333F
 
#define ONEOVER48   0.02083333333F
 
#define ONEOVER120   0.0083333333F
 
#define ONEOVER3840   0.0002604166667F
 
#define ONEOVERSQRT2   0.707106781F
 
#define SQRT15OVER4   0.968245837F
 

Typedefs

typedef enum quaternion quaternion_type
 
typedef int8_t( initializeSensor_t) (struct PhysicalSensor *sensor, struct SensorFusionGlobals *sfg)
 
typedef int8_t( readSensor_t) (struct PhysicalSensor *sensor, struct SensorFusionGlobals *sfg)
 
typedef int8_t( readSensors_t) (struct SensorFusionGlobals *sfg, uint16_t read_loop_counter)
 
typedef int8_t( installSensor_t) (struct SensorFusionGlobals *sfg, struct PhysicalSensor *sensor, uint16_t addr, uint16_t schedule, void *bus_driver, initializeSensor_t *initialize, readSensor_t *read)
 
typedef void( initializeFusionEngine_t) (struct SensorFusionGlobals *sfg)
 
typedef void( runFusion_t) (struct SensorFusionGlobals *sfg)
 
typedef void( clearFIFOs_t) (struct SensorFusionGlobals *sfg)
 
typedef void( conditionSensorReadings_t) (struct SensorFusionGlobals *sfg)
 
typedef void( applyPerturbation_t) (struct SensorFusionGlobals *sfg)
 
typedef void( setStatus_t) (struct SensorFusionGlobals *sfg, fusion_status_t status)
 
typedef void( updateStatus_t) (struct SensorFusionGlobals *sfg)
 
typedef void( ssSetStatus_t) (struct StatusSubsystem *pStatus, fusion_status_t status)
 
typedef void( ssUpdateStatus_t) (struct StatusSubsystem *pStatus)
 
typedef struct PhysicalSensor PhysicalSensor
 
typedef struct PressureSensor PressureSensor
 
typedef struct AccelSensor AccelSensor
 
typedef struct MagSensor MagSensor
 
typedef struct GyroSensor GyroSensor
 
typedef union FifoSensor FifoSensor
 
typedef struct SV_1DOF_P_BASIC SV_1DOF_P_BASIC
 
typedef struct SV_3DOF_G_BASIC SV_3DOF_G_BASIC
 
typedef struct SV_3DOF_B_BASIC SV_3DOF_B_BASIC
 
typedef struct SV_3DOF_Y_BASIC SV_3DOF_Y_BASIC
 
typedef struct SV_6DOF_GB_BASIC SV_6DOF_GB_BASIC
 
typedef struct SV_6DOF_GY_KALMAN SV_6DOF_GY_KALMAN
 
typedef struct SV_9DOF_GBY_KALMAN SV_9DOF_GBY_KALMAN
 
typedef struct SV_COMMON SV_COMMON
 
typedef SV_COMMONSV_ptr
 
typedef struct SensorFusionGlobals SensorFusionGlobals
 
Integer Typedefs

Typedefs to map common integer types to standard form

typedef unsigned char byte
 
typedef int8_t int8
 
typedef int16_t int16
 
typedef int32_t int32
 
typedef uint8_t uint8
 
typedef uint16_t uint16
 
typedef uint32_t uint32
 

Enumerations

enum  quaternion {
  Q3, Q3M, Q3G, Q6MA,
  Q6AG, Q9
}
 
enum  fusion_status_t {
  OFF, INITIALIZING, LOWPOWER, NORMAL,
  RECEIVING_WIRED, RECEIVING_WIRELESS, HARD_FAULT, SOFT_FAULT
}
 

Functions

void initSensorFusionGlobals (SensorFusionGlobals *sfg, struct StatusSubsystem *pStatusSubsystem, struct ControlSubsystem *pControlSubsystem)
 
void conditionSensorReadings (SensorFusionGlobals *sfg)
 
void clearFIFOs (SensorFusionGlobals *sfg)
 
void zeroArray (struct StatusSubsystem *pStatus, void *data, uint16_t size, uint16_t numElements, uint8_t check)
 
void conditionSample (int16_t sample[3])
 
void addToFifo (FifoSensor *sensor, uint16_t maxFifoSize, int16_t sample[3])
 
void ApplyAccelHAL (AccelSensor *Accel)
 
void ApplyMagHAL (MagSensor *Mag)
 
void ApplyGyroHAL (GyroSensor *Gyro)
 

Variables

installSensor_t installSensor
 
initializeFusionEngine_t initializeFusionEngine
 
runFusion_t runFusion
 
readSensors_t readSensors
 
applyPerturbation_t ApplyPerturbation
 

Macro Definition Documentation

#define B0   (1 << 0)

Definition at line 88 of file sensor_fusion.h.

Referenced by fusion_task(), and read_task().

#define B1   (1 << 1)

Definition at line 89 of file sensor_fusion.h.

#define B2   (1 << 2)

Definition at line 90 of file sensor_fusion.h.

#define B3   (1 << 3)

Definition at line 91 of file sensor_fusion.h.

#define F180OVERPI   57.2957795130823F

radians to degrees conversion = 180 / pi

Definition at line 100 of file sensor_fusion.h.

Referenced by ApplyPerturbation(), and fRotationVectorDegFromQuaternion().

#define F180OVERPISQ   3282.8063500117F

square of F180OVERPI

Definition at line 101 of file sensor_fusion.h.

#define false   0

Boolean FALSE.

Definition at line 83 of file sensor_fusion.h.

#define FPIOVER180   0.01745329251994F

degrees to radians conversion = pi / 180

Definition at line 99 of file sensor_fusion.h.

Referenced by fInit_6DOF_GY_KALMAN(), fInit_9DOF_GBY_KALMAN(), fQuaternionFromRotationVectorDeg(), and fRotationVectorDegFromQuaternion().

#define GTOMSEC2   9.80665

Referenced by fInit_9DOF_GBY_KALMAN().

#define ONEOVER12   0.083333333F

1 / 12

Definition at line 105 of file sensor_fusion.h.

Referenced by fRun_6DOF_GY_KALMAN().

#define ONEOVER120   0.0083333333F

1 / 120

Definition at line 107 of file sensor_fusion.h.

#define ONEOVER3840   0.0002604166667F

1 / 3840

Definition at line 108 of file sensor_fusion.h.

Referenced by fQuaternionFromRotationVectorDeg().

#define ONEOVER48   0.02083333333F

1 / 48

Definition at line 106 of file sensor_fusion.h.

Referenced by fQuaternionFromRotationVectorDeg().

#define ONEOVERSQRT2   0.707106781F

1/sqrt(2)

Definition at line 109 of file sensor_fusion.h.

Referenced by ApplyPerturbation(), and fveqconjgquq().

#define ONESIXTEENTH   0.0625F

one sixteenth

Definition at line 104 of file sensor_fusion.h.

#define ONESIXTH   0.166666667F

one sixth

Definition at line 103 of file sensor_fusion.h.

Referenced by fComputeMagCalibration10(), and fComputeMagCalibration7().

#define ONETHIRD   0.33333333F
#define PI   3.141592654F

pi

Definition at line 97 of file sensor_fusion.h.

Referenced by fInitializeMagCalibration().

#define PIOVER2   1.570796327F

pi / 2

Definition at line 98 of file sensor_fusion.h.

#define SPI_ADDR   0x00

Definition at line 153 of file sensor_fusion.h.

Referenced by FXLS8471Q_Idle(), FXLS8471Q_Init(), and FXLS8471Q_Read().

#define SQRT15OVER4   0.968245837F

sqrt(15)/4

Definition at line 110 of file sensor_fusion.h.

#define true   1

Boolean TRUE.

Definition at line 82 of file sensor_fusion.h.

Typedef Documentation

typedef struct AccelSensor AccelSensor

The AccelSensor structure stores raw and processed measurements for a 3-axis accelerometer.

The AccelSensor structure stores raw and processed measurements, as well as metadata for a single 3-axis accelerometer. This structure is normally "fed" by the sensor driver and "consumed" by the fusion routines.

typedef void( applyPerturbation_t) (struct SensorFusionGlobals *sfg)

Definition at line 160 of file sensor_fusion.h.

typedef unsigned char byte

Definition at line 54 of file sensor_fusion.h.

typedef void( clearFIFOs_t) (struct SensorFusionGlobals *sfg)

Definition at line 158 of file sensor_fusion.h.

typedef void( conditionSensorReadings_t) (struct SensorFusionGlobals *sfg)

Definition at line 159 of file sensor_fusion.h.

typedef union FifoSensor FifoSensor

The FifoSensor union allows us to use common pointers for Accel, Mag & Gyro logical sensor structures.

Common elements include: iWhoAmI, isEnabled, iFIFOCount, iFIFOExceeded and the FIFO itself.

typedef struct GyroSensor GyroSensor

The GyroSensor structure stores raw and processed measurements for a 3-axis gyroscope.

The GyroSensor structure stores raw and processed measurements, as well as metadata for a single 3-axis gyroscope. This structure is normally "fed" by the sensor driver and "consumed" by the fusion routines.

typedef void( initializeFusionEngine_t) (struct SensorFusionGlobals *sfg)

Definition at line 156 of file sensor_fusion.h.

typedef int8_t( initializeSensor_t) (struct PhysicalSensor *sensor, struct SensorFusionGlobals *sfg)

Definition at line 132 of file sensor_fusion.h.

typedef int8_t( installSensor_t) (struct SensorFusionGlobals *sfg, struct PhysicalSensor *sensor, uint16_t addr, uint16_t schedule, void *bus_driver, initializeSensor_t *initialize, readSensor_t *read)

Definition at line 144 of file sensor_fusion.h.

typedef int16_t int16

Definition at line 56 of file sensor_fusion.h.

typedef int32_t int32

Definition at line 57 of file sensor_fusion.h.

typedef int8_t int8

Definition at line 55 of file sensor_fusion.h.

typedef struct MagSensor MagSensor

The MagSensor structure stores raw and processed measurements for a 3-axis magnetic sensor.

The MagSensor structure stores raw and processed measurements, as well as metadata for a single 3-axis magnetometer. This structure is normally "fed" by the sensor driver and "consumed" by the fusion routines.

An instance of PhysicalSensor structure type should be allocated for each physical sensors (combo devices = 1)

These structures sit 'on-top-of' the pre-7.0 sensor fusion structures and give us the ability to do run time driver installation.

The PressureSensor structure stores raw and processed measurements for an altimeter.

The PressureSensor structure stores raw and processed measurements, as well as metadata for a pressure sensor/altimeter.

the quaternion type to be transmitted

typedef int8_t( readSensor_t) (struct PhysicalSensor *sensor, struct SensorFusionGlobals *sfg)

Definition at line 136 of file sensor_fusion.h.

typedef int8_t( readSensors_t) (struct SensorFusionGlobals *sfg, uint16_t read_loop_counter)

Definition at line 140 of file sensor_fusion.h.

typedef void( runFusion_t) (struct SensorFusionGlobals *sfg)

Definition at line 157 of file sensor_fusion.h.

The top level fusion structure.

The top level fusion structure grows/shrinks based upon flag definitions contained in build.h. These same flags will populate the .iFlags field for run-time access.

typedef void( setStatus_t) (struct SensorFusionGlobals *sfg, fusion_status_t status)

Definition at line 161 of file sensor_fusion.h.

typedef void( ssSetStatus_t) (struct StatusSubsystem *pStatus, fusion_status_t status)

Definition at line 163 of file sensor_fusion.h.

typedef void( ssUpdateStatus_t) (struct StatusSubsystem *pStatus)

Definition at line 164 of file sensor_fusion.h.

The SV_1DOF_P_BASIC structure contains state information for a pressure sensor/altimeter.

This is the 3DOF basic magnetometer state vector structure/.

This is the 3DOF basic accelerometer state vector structure.

SV_3DOF_Y_BASIC structure is the 3DOF basic gyroscope state vector structure.

SV_6DOF_GB_BASIC is the 6DOF basic accelerometer and magnetometer state vector structure.

SV_6DOF_GY_KALMAN is the 6DOF Kalman filter accelerometer and gyroscope state vector structure.

SV_9DOF_GBY_KALMAN is the 9DOF Kalman filter accelerometer, magnetometer and gyroscope state vector structure.

typedef struct SV_COMMON SV_COMMON

Excluding SV_1DOF_P_BASIC, Any of the SV_ fusion structures above could be cast to type SV_COMMON for dereferencing.

typedef SV_COMMON* SV_ptr

Definition at line 460 of file sensor_fusion.h.

typedef uint16_t uint16

Definition at line 59 of file sensor_fusion.h.

typedef uint32_t uint32

Definition at line 60 of file sensor_fusion.h.

typedef uint8_t uint8

Definition at line 58 of file sensor_fusion.h.

typedef void( updateStatus_t) (struct SensorFusionGlobals *sfg)

Definition at line 162 of file sensor_fusion.h.

Enumeration Type Documentation

Application-specific serial communications system.

Enumerator
OFF 

These are the state definitions for the status subsystem.

Application hasn't started

INITIALIZING 

Initializing sensors and algorithms.

LOWPOWER 

Running in reduced power mode.

NORMAL 

Operation is Nominal.

RECEIVING_WIRED 

Receiving commands over wired interface (momentary)

RECEIVING_WIRELESS 

Receiving commands over wireless interface (momentary)

HARD_FAULT 

Non-recoverable FAULT = something went very wrong.

SOFT_FAULT 

Recoverable FAULT = something went wrong, but we can keep going.

Definition at line 120 of file sensor_fusion.h.

120  { /// These are the state definitions for the status subsystem
121  OFF, ///< Application hasn't started
122  INITIALIZING, ///< Initializing sensors and algorithms
123  LOWPOWER, ///< Running in reduced power mode
124  NORMAL, ///< Operation is Nominal
125  RECEIVING_WIRED, ///< Receiving commands over wired interface (momentary)
126  RECEIVING_WIRELESS, ///< Receiving commands over wireless interface (momentary)
127  HARD_FAULT, ///< Non-recoverable FAULT = something went very wrong
128  SOFT_FAULT ///< Recoverable FAULT = something went wrong, but we can keep going
Initializing sensors and algorithms.
Receiving commands over wireless interface (momentary)
These are the state definitions for the status subsystem.
Recoverable FAULT = something went wrong, but we can keep going.
Receiving commands over wired interface (momentary)
Running in reduced power mode.
Non-recoverable FAULT = something went very wrong.
fusion_status_t
Application-specific serial communications system.
Operation is Nominal.
enum quaternion

the quaternion type to be transmitted

Enumerator
Q3 

Quaternion derived from 3-axis accel (tilt)

Q3M 

Quaternion derived from 3-axis mag only (auto compass algorithm)

Q3G 

Quaternion derived from 3-axis gyro only (rotation)

Q6MA 

Quaternion derived from 3-axis accel + 3 axis mag (eCompass)

Q6AG 

Quaternion derived from 3-axis accel + 3-axis gyro (gaming)

Q9 

Quaternion derived from full 9-axis sensor fusion.

Definition at line 64 of file sensor_fusion.h.

64  {
65  Q3, ///< Quaternion derived from 3-axis accel (tilt)
66  Q3M, ///< Quaternion derived from 3-axis mag only (auto compass algorithm)
67  Q3G, ///< Quaternion derived from 3-axis gyro only (rotation)
68  Q6MA, ///< Quaternion derived from 3-axis accel + 3 axis mag (eCompass)
69  Q6AG, ///< Quaternion derived from 3-axis accel + 3-axis gyro (gaming)
70  Q9 ///< Quaternion derived from full 9-axis sensor fusion
enum quaternion quaternion_type
the quaternion type to be transmitted
Quaternion derived from full 9-axis sensor fusion.
Definition: sensor_fusion.h:70
Quaternion derived from 3-axis mag only (auto compass algorithm)
Definition: sensor_fusion.h:66
Quaternion derived from 3-axis gyro only (rotation)
Definition: sensor_fusion.h:67
Quaternion derived from 3-axis accel + 3 axis mag (eCompass)
Definition: sensor_fusion.h:68
Quaternion derived from 3-axis accel + 3-axis gyro (gaming)
Definition: sensor_fusion.h:69
Quaternion derived from 3-axis accel (tilt)
Definition: sensor_fusion.h:65

Function Documentation

void addToFifo ( FifoSensor sensor,
uint16_t  maxFifoSize,
int16_t  sample[3] 
)

addToFifo is called from within sensor driver read functions

addToFifo is called from within sensor driver read functions to transfer new readings into the sensor structure corresponding to accel, gyro or mag. This function ensures that the software FIFOs are not overrun.

example usage: if (status==SENSOR_ERROR_NONE) addToFifo((FifoSensor*) &(sfg->Mag), MAG_FIFO_SIZE, sample);

Parameters
sensorpointer to structure of type AccelSensor, MagSensor or GyroSensor
maxFifoSizethe size of the software (not hardware) FIFO
samplethe sample to add

Definition at line 531 of file sensor_fusion.c.

Referenced by FXLS8471Q_Read(), FXOS8700_Init(), FXOS8700_ReadMagData(), and MAG3110_Read().

532 {
533  // Note that FifoSensor is a union of GyroSensor, MagSensor and AccelSensor.
534  // All contain FIFO structures in the same location. We use the Accel
535  // structure to index here.
536 
537  // example usage: if (status==SENSOR_ERROR_NONE) addToFifo((FifoSensor*) &(sfg->Mag), MAG_FIFO_SIZE, sample);
538  uint8_t fifoCount = sensor->Accel.iFIFOCount;
539  if (fifoCount < maxFifoSize) {
540  // we have room for the new sample
541  sensor->Accel.iGsFIFO[fifoCount][CHX] = sample[CHX];
542  sensor->Accel.iGsFIFO[fifoCount][CHY] = sample[CHY];
543  sensor->Accel.iGsFIFO[fifoCount][CHZ] = sample[CHZ];
544  sensor->Accel.iFIFOCount += 1;
545  sensor->Accel.iFIFOExceeded = 0;
546  } else {
547  //there is no room for a new sample
548  sensor->Accel.iFIFOExceeded += 1;
549  }
550 }
int16_t iGsFIFO[ACCEL_FIFO_SIZE][3]
FIFO measurements (counts)
#define CHY
Used to access Y-channel entries in various data data structures.
Definition: sensor_fusion.h:77
uint16_t iFIFOExceeded
Number of samples received in excess of software FIFO size.
AccelSensor Accel
#define CHZ
#define CHX
Used to access X-channel entries in various data data structures.
Definition: sensor_fusion.h:76
uint8_t iFIFOCount
number of measurements read from FIFO

+ Here is the caller graph for this function:

void ApplyAccelHAL ( AccelSensor Accel)

Apply the accelerometer Hardware Abstraction Layer.

Parameters
Accelpointer to accelerometer logical sensor

Definition at line 44 of file hal_frdm_fxs_mult2_b.c.

Referenced by initializeSensors().

45 {
46  int8 i; // loop counter
47 
48  // apply HAL to all measurements read from FIFO buffer
49  for (i = 0; i < Accel->iFIFOCount; i++)
50  {
51  // apply HAL mapping to coordinate system used
52 #if THISCOORDSYSTEM == NED
53  int16 itmp16 = Accel->iGsFIFO[i][CHX];
54  Accel->iGsFIFO[i][CHX] = Accel->iGsFIFO[i][CHY];
55  Accel->iGsFIFO[i][CHY] = itmp16;
56 #endif // NED
57 #if THISCOORDSYSTEM == ANDROID
58  Accel->iGsFIFO[i][CHX] = -Accel->iGsFIFO[i][CHX];
59  Accel->iGsFIFO[i][CHY] = -Accel->iGsFIFO[i][CHY];
60 #endif // Android
61 #if (THISCOORDSYSTEM == WIN8)
62  Accel->iGsFIFO[i][CHZ] = -Accel->iGsFIFO[i][CHZ];
63 #endif // Win8
64 
65  } // end of loop over FIFO count
66 
67  return;
68 }
int16_t iGsFIFO[ACCEL_FIFO_SIZE][3]
FIFO measurements (counts)
#define CHY
Used to access Y-channel entries in various data data structures.
Definition: sensor_fusion.h:77
#define CHZ
#define CHX
Used to access X-channel entries in various data data structures.
Definition: sensor_fusion.h:76
uint8_t iFIFOCount
number of measurements read from FIFO
int16_t int16
Definition: sensor_fusion.h:56
int8_t int8
Definition: sensor_fusion.h:55

+ Here is the caller graph for this function:

void ApplyGyroHAL ( GyroSensor Gyro)

Apply the gyroscope Hardware Abstraction Layer.

Parameters
Gyropointer to gyroscope logical sensor

Definition at line 99 of file hal_frdm_fxs_mult2_b.c.

Referenced by processMagData().

100 {
101  int8 i; // loop counter
102 
103  // apply HAL to all measurements read from FIFO buffer
104  for (i = 0; i < Gyro->iFIFOCount; i++)
105  {
106  // apply HAL mapping to coordinate system used
107 #if THISCOORDSYSTEM == NED
108  int16 itmp16 = Gyro->iYsFIFO[i][CHX];
109  Gyro->iYsFIFO[i][CHX] = -Gyro->iYsFIFO[i][CHY];
110  Gyro->iYsFIFO[i][CHY] = -itmp16;
111  Gyro->iYsFIFO[i][CHZ] = -Gyro->iYsFIFO[i][CHZ];
112 #endif // NED
113 #if THISCOORDSYSTEM == ANDROID
114  Gyro->iYsFIFO[i][CHX] = -Gyro->iYsFIFO[i][CHX];
115  Gyro->iYsFIFO[i][CHY] = -Gyro->iYsFIFO[i][CHY];
116 #endif // Android
117 #if THISCOORDSYSTEM == WIN8
118  Gyro->iYsFIFO[i][CHX] = -Gyro->iYsFIFO[i][CHX];
119  Gyro->iYsFIFO[i][CHY] = -Gyro->iYsFIFO[i][CHY];
120 #endif // Win8
121 
122  } // end of loop over FIFO count
123 
124  return;
125 }
#define CHY
Used to access Y-channel entries in various data data structures.
Definition: sensor_fusion.h:77
uint8_t iFIFOCount
number of measurements read from FIFO
#define CHZ
int16_t iYsFIFO[GYRO_FIFO_SIZE][3]
FIFO measurements (counts)
#define CHX
Used to access X-channel entries in various data data structures.
Definition: sensor_fusion.h:76
int16_t int16
Definition: sensor_fusion.h:56
int8_t int8
Definition: sensor_fusion.h:55

+ Here is the caller graph for this function:

void ApplyMagHAL ( MagSensor Mag)

Apply the magnetometer Hardware Abstraction Layer.

Parameters
Magpointer to magnetometer logical sensor

Definition at line 71 of file hal_frdm_fxs_mult2_b.c.

Referenced by processMagData().

72 {
73  int8 i; // loop counter
74 
75  // apply HAL to all measurements read from FIFO buffer
76  for (i = 0; i < Mag->iFIFOCount; i++)
77  {
78  // apply HAL mapping to coordinate system used
79 #if THISCOORDSYSTEM == NED
80  int16 itmp16 = Mag->iBsFIFO[i][CHX];
81  Mag->iBsFIFO[i][CHX] = -Mag->iBsFIFO[i][CHY];
82  Mag->iBsFIFO[i][CHY] = -itmp16;
83  Mag->iBsFIFO[i][CHZ] = -Mag->iBsFIFO[i][CHZ];
84 #endif // NED
85 #if THISCOORDSYSTEM == ANDROID
86  Mag->iBsFIFO[i][CHX] = -Mag->iBsFIFO[i][CHX];
87  Mag->iBsFIFO[i][CHY] = -Mag->iBsFIFO[i][CHY];
88 #endif // Android
89 #if THISCOORDSYSTEM == WIN8
90  Mag->iBsFIFO[i][CHX] = -Mag->iBsFIFO[i][CHX];
91  Mag->iBsFIFO[i][CHY] = -Mag->iBsFIFO[i][CHY];
92 #endif
93  } // end of loop over FIFO count
94 
95  return;
96 }
#define CHY
Used to access Y-channel entries in various data data structures.
Definition: sensor_fusion.h:77
#define CHZ
uint8_t iFIFOCount
number of measurements read from FIFO
#define CHX
Used to access X-channel entries in various data data structures.
Definition: sensor_fusion.h:76
int16_t iBsFIFO[MAG_FIFO_SIZE][3]
FIFO measurements (counts)
int16_t int16
Definition: sensor_fusion.h:56
int8_t int8
Definition: sensor_fusion.h:55

+ Here is the caller graph for this function:

void clearFIFOs ( SensorFusionGlobals sfg)

Function to clear FIFO at the end of each fusion computation.

Parameters
sfgGlobal data structure pointer

Definition at line 363 of file sensor_fusion.c.

Referenced by initializeFusionEngine(), initSensorFusionGlobals(), and runFusion().

363  {
364  // We only clear FIFOs if the sensors are enabled. This allows us
365  // to continue to use these values when we've shut higher power consumption
366  // sensors down during periods of no activity.
367 #if F_USING_ACCEL
368  sfg->Accel.iFIFOCount=0;
369  sfg->Accel.iFIFOExceeded = false;
370 #endif
371 #if F_USING_MAG
372  sfg->Mag.iFIFOCount=0;
373  sfg->Mag.iFIFOExceeded = false;
374 #endif
375 #if F_USING_GYRO
376  sfg->Gyro.iFIFOCount=0;
377  sfg->Gyro.iFIFOExceeded = false;
378 #endif
379 }
MagSensor Mag
magnetometer storage
uint8_t iFIFOCount
number of measurements read from FIFO
uint16_t iFIFOExceeded
Number of samples received in excess of software FIFO size.

+ Here is the caller graph for this function:

void conditionSample ( int16_t  sample[3])

conditionSample ensures that we never encounter the maximum negative two's complement value for a 16-bit variable (-32768).

conditionSample ensures that we never encounter the maximum negative two's complement value for a 16-bit variable (-32768). This value cannot be negated, because the maximum positive value is +32767. We need the ability to negate to gaurantee that subsequent HAL operations can be run successfully.

Parameters
sample16-bit register value from triaxial sensor read

Definition at line 519 of file sensor_fusion.c.

Referenced by FXLS8471Q_Read(), FXOS8700_Init(), FXOS8700_ReadMagData(), and MAG3110_Read().

520 {
521  // This function should be called for every 16 bit sample read from sensor hardware.
522  // It is responsible for making sure that we never pass on the value of -32768.
523  // That value cannot be properly negated using 16-bit twos complement math.
524  // The ability to be later negated is required for general compatibility
525  // with possible HAL (Hardware abstraction logic) which is run later in
526  // the processing pipeline.
527  if (sample[CHX] == -32768) sample[CHX]++;
528  if (sample[CHY] == -32768) sample[CHY]++;
529  if (sample[CHZ] == -32768) sample[CHZ]++;
530 }
#define CHY
Used to access Y-channel entries in various data data structures.
Definition: sensor_fusion.h:77
#define CHZ
#define CHX
Used to access X-channel entries in various data data structures.
Definition: sensor_fusion.h:76

+ Here is the caller graph for this function:

void conditionSensorReadings ( SensorFusionGlobals sfg)

conditionSensorReadings() transforms raw software FIFO readings into forms that can be consumed by the sensor fusion engine. This include sample averaging and (in the case of the gyro) integrations, applying hardware abstraction layers, and calibration functions. This function is normally involved via the "sfg." global pointer.

Parameters
sfgGlobal data structure pointer

Definition at line 305 of file sensor_fusion.c.

Referenced by initSensorFusionGlobals().

305  {
306 #if F_USING_ACCEL
307  if (sfg->Accel.isEnabled) processAccelData(sfg);
308 #endif
309 
310 #if F_USING_MAG
311  if (sfg->Mag.isEnabled) processMagData(sfg);
312 #endif
313 
314 #if F_USING_GYRO
315  if (sfg->Gyro.isEnabled) processGyroData(sfg);
316 #endif
317  return;
318 }
void processMagData(SensorFusionGlobals *sfg)
MagSensor Mag
magnetometer storage
bool isEnabled
true if the device is sampling

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void initSensorFusionGlobals ( SensorFusionGlobals sfg,
struct StatusSubsystem pStatusSubsystem,
struct ControlSubsystem pControlSubsystem 
)

utility function to insert default values in the top level structure

Parameters
sfgGlobal data structure pointer
pStatusSubsystemStatus subsystem pointer
pControlSubsystemControl subsystem pointer

Definition at line 68 of file sensor_fusion.c.

Referenced by main().

71 {
72  sfg->iFlags = // all of the following defines are either 0x0000 or a 1-bit value (2, 4, 8 ...) and are defined in build.h
74  F_USING_MAG |
75  F_USING_GYRO |
78  F_ALL_SENSORS | // refers to all applicable sensor types for the given physical unit
79  F_1DOF_P_BASIC | // 1DOF pressure (altitude) and temperature: (pressure)
80  F_3DOF_G_BASIC | // 3DOF accel tilt: (accel)
81  F_3DOF_B_BASIC | // 3DOF mag eCompass (vehicle): (mag)
82  F_3DOF_Y_BASIC | // 3DOF gyro integration: (gyro)
83  F_6DOF_GB_BASIC | // 6DOF accel and mag eCompass)
84  F_6DOF_GY_KALMAN | // 6DOF accel and gyro (Kalman): (accel + gyro)
85  F_9DOF_GBY_KALMAN ; // 9DOF accel, mag and gyro (Kalman): (accel + mag + gyro)
86 
87  sfg->pControlSubsystem = pControlSubsystem;
88  sfg->pStatusSubsystem = pStatusSubsystem;
89  sfg->loopcounter = 0; // counter incrementing each iteration of sensor fusion (typically 25Hz)
90  sfg->systick_I2C = 0; // systick counter to benchmark I2C reads
91  sfg->systick_Spare = 0; // systick counter for counts spare waiting for timing interrupt
92  sfg->iPerturbation = 0; // no perturbation to be applied
93  sfg->installSensor = installSensor; // function for installing a new sensor into the structures
94  sfg->initializeFusionEngine = initializeFusionEngine; // function for installing a new sensor into the structures
95  sfg->readSensors = readSensors; // function for installing a new sensor into the structures
96  sfg->runFusion = runFusion; // function for installing a new sensor into the structures
97  sfg->applyPerturbation = ApplyPerturbation; // function used for step function testing
98  sfg->conditionSensorReadings = conditionSensorReadings; // function does averaging, HAL adjustments, etc.
99  sfg->clearFIFOs = clearFIFOs; // function to clear FIFO flags sfg->applyPerturbation = ApplyPerturbation; // function used for step function testing
100  sfg->setStatus = setStatus; // function to immediately set status change
101  sfg->queueStatus = queueStatus; // function to queue status change
102  sfg->updateStatus = updateStatus; // function to promote queued status change
103  sfg->testStatus = testStatus; // function for unit testing the status subsystem
104  sfg->pSensors = NULL; // pointer to linked list of physical sensors
105 // put error value into whoAmI as initial value
106 #if F_USING_ACCEL
107  sfg->Accel.iWhoAmI = 0;
108 #endif
109 #if F_USING_MAG
110  sfg->Mag.iWhoAmI = 0;
111 #endif
112 #if F_USING_GYRO
113  sfg->Gyro.iWhoAmI = 0;
114 #endif
115 #if F_USING_PRESSURE
116  sfg->Pressure.iWhoAmI = 0;
117 #endif
118 }
#define F_USING_GYRO
nominally 0x0004 if a gyro is to be used, 0x0000 otherwise
int32_t loopcounter
counter incrementing each iteration of sensor fusion (typically 25Hz)
clearFIFOs_t * clearFIFOs
clear sensor FIFOs
int32_t systick_I2C
systick counter to benchmark I2C reads
#define F_ALL_SENSORS
uint32_t iFlags
a bit-field of sensors and algorithms used
conditionSensorReadings_t * conditionSensorReadings
preprocessing step for sensor fusion
void setStatus(SensorFusionGlobals *sfg, fusion_status_t status)
Poor man&#39;s inheritance for status subsystem setStatus command This function is normally involved via ...
Definition: sensor_fusion.c:43
#define F_USING_PRESSURE
nominally 0x0008 if altimeter is to be used, 0x0000 otherwise
installSensor_t * installSensor
function for installing a new sensor into t
int8_t installSensor(SensorFusionGlobals *sfg, PhysicalSensor *pSensor, uint16_t addr, uint16_t schedule, void *bus_driver, initializeSensor_t *initialize, readSensor_t *read)
installSensor is used to instantiate a physical sensor driver into the sensor fusion system...
void testStatus(SensorFusionGlobals *sfg)
Definition: sensor_fusion.c:62
void initializeFusionEngine(SensorFusionGlobals *sfg)
This function is responsible for initializing the system prior to starting the main fusion loop...
void clearFIFOs(SensorFusionGlobals *sfg)
Function to clear FIFO at the end of each fusion computation.
readSensors_t * readSensors
read all physical sensors
struct ControlSubsystem * pControlSubsystem
initializeFusionEngine_t * initializeFusionEngine
set sensor fusion structures to initial values
MagSensor Mag
magnetometer storage
#define F_1DOF_P_BASIC
1DOF pressure (altitude) and temperature algorithm selector - 0x0100 to include, 0x0000 otherwise ...
#define F_9DOF_GBY_KALMAN
updateStatus_t * updateStatus
status=next status
int8_t readSensors(SensorFusionGlobals *sfg, uint16_t read_loop_counter)
readSensors traverses the linked list of physical sensors, calling the individual read functions one ...
#define F_6DOF_GY_KALMAN
6DOF accel and gyro (Kalman) algorithm selector - 0x2000 to include, 0x0000 otherwise ...
void runFusion(SensorFusionGlobals *sfg)
runFusion the top level call that actually runs the sensor fusion. This is a utility function which m...
#define F_3DOF_G_BASIC
3DOF accel tilt (accel) algorithm selector - 0x0200 to include, 0x0000 otherwise
void queueStatus(SensorFusionGlobals *sfg, fusion_status_t status)
Poor man&#39;s inheritance for status subsystem queueStatus command. This function is normally involved v...
Definition: sensor_fusion.c:50
#define F_USING_TEMPERATURE
nominally 0x0010 if temp sensor is to be used, 0x0000 otherwise
runFusion_t * runFusion
run the fusion routines
struct StatusSubsystem * pStatusSubsystem
void conditionSensorReadings(SensorFusionGlobals *sfg)
conditionSensorReadings() transforms raw software FIFO readings into forms that can be consumed by th...
uint8_t iWhoAmI
sensor whoami
void updateStatus(SensorFusionGlobals *sfg)
Poor man&#39;s inheritance for status subsystem updateStatus command. This function is normally involved ...
Definition: sensor_fusion.c:57
#define F_3DOF_Y_BASIC
3DOF gyro integration algorithm selector - 0x0800 to include, 0x0000 otherwise
setStatus_t * queueStatus
queue status change for next regular interval
#define F_6DOF_GB_BASIC
6DOF accel and mag eCompass algorithm selector - 0x1000 to include, 0x0000 otherwise ...
#define F_USING_ACCEL
nominally 0x0001 if an accelerometer is to be used, 0x0000 otherwise
setStatus_t * setStatus
change status indicator immediately
applyPerturbation_t * applyPerturbation
apply step function for testing purposes
#define F_3DOF_B_BASIC
3DOF mag eCompass (vehicle/mag) algorithm selector - 0x0400 to include, 0x0000 otherwise ...
#define F_USING_MAG
Definition: magnetic.h:38
volatile uint8_t iPerturbation
test perturbation to be applied
applyPerturbation_t ApplyPerturbation
ApplyPerturbation is a reverse unit-step test function.
PhysicalSensor * pSensors
a linked list of physical sensors

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void zeroArray ( struct StatusSubsystem pStatus,
void *  data,
uint16_t  size,
uint16_t  numElements,
uint8_t  check 
)
Parameters
pStatusStatus subsystem pointer
datapointer to array to be zeroed
sizedata type size = 8, 16 or 32
numElementsnumber of elements to zero out
checktrue if you would like to verify writes, false otherwise

Definition at line 320 of file sensor_fusion.c.

320  {
321  uint16_t i;
322  uint8_t *d8;
323  uint16_t *d16;
324  uint32_t *d32;
325  switch(size) {
326  case 8:
327  d8 = data;
328  for (i=0; i<numElements; i++) d8[i]=0;
329  break;
330  case 16:
331  d16 = data;
332  for (i=0; i<numElements; i++) d16[i]=0;
333  break;
334  case 32:
335  d32 = data;
336  for (i=0; i<numElements; i++) d32[i]=0;
337  break;
338  default:
339  pStatus->set(pStatus, HARD_FAULT);
340  }
341  if (check) {
342  switch(size) {
343  case 8:
344  d8 = data;
345  for (i=0; i<numElements; i++)
346  if (d8[i]!=0) pStatus->set(pStatus, HARD_FAULT);
347  break;
348  case 16:
349  d16 = data;
350  for (i=0; i<numElements; i++)
351  if (d16[i]!=0) pStatus->set(pStatus, HARD_FAULT);
352  break;
353  case 32:
354  d32 = data;
355  for (i=0; i<numElements; i++)
356  if (d32[i]!=0) pStatus->set(pStatus, HARD_FAULT);
357  break;
358  }
359  return;
360  }
361 }
Non-recoverable FAULT = something went very wrong.
ssSetStatus_t * set
change status immediately - no delay
Definition: status.h:50

Variable Documentation

applyPerturbation_t ApplyPerturbation

ApplyPerturbation is a reverse unit-step test function.

The ApplyPerturbation function applies a user-specified step function to prior fusion results which is then "released" in the next fusion cycle. When used in conjuction with the NXP Sensor Fusion Toolbox, this provides a visual indication of the dynamic behavior of the library. ApplyPerturbation() is defined in debug.c.

Definition at line 626 of file sensor_fusion.h.

Referenced by initSensorFusionGlobals().

initializeFusionEngine_t initializeFusionEngine

Definition at line 558 of file sensor_fusion.h.

installSensor_t installSensor

Definition at line 557 of file sensor_fusion.h.

readSensors_t readSensors

Definition at line 571 of file sensor_fusion.h.

runFusion_t runFusion

Definition at line 570 of file sensor_fusion.h.